package com.atguigu.day21.file01;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.Date;
/*
File: 与平台无关的文件或文件夹
 */

public class FileTest {

    public static void main(String[] args) throws IOException {
        File f = new File("main.txt");
        f.createNewFile();
    }
    @Test
    public void test07(){
        File f = new File("dd.txt");
        //相对路径 模块
        System.out.println("f.getPath() = " + f.getPath());
        //绝对路径 磁盘
        System.out.println("f.getAbsolutePath() = " + f.getAbsolutePath());

    }

    @Test
    public void test06() throws IOException {

        File f = new File("dd.txt");
        f.createNewFile();
    }




    @Test
    public void test05(){

        File f = new File("D:/cc/a/b/c");

       // f.mkdir(); 单层文件夹
        //f.mkdirs();//多层文件夹

        boolean delete = f.delete();//只能删除空文件夹
        System.out.println("delete = " + delete);

    }


    @Test
    public void test04() throws IOException {

        File f = new File("D:/hero.txt");

        boolean exists = f.exists();

        if(exists){
            System.out.println("存在删除");
            //不经过回收站
            f.delete();
        }else{
            System.out.println("不存在 创建");
            f.createNewFile();
        }


    }

    @Test
    public void test03(){
        File f = new File("D:/a.txt");
        //判断是否为文件
        System.out.println("f.isFile() = " + f.isFile());
        //判断是否为文件夹
        System.out.println("f.isDirectory() = " + f.isDirectory());
        //判断是否存在
        System.out.println("f.exists() = " + f.exists());


    }

    @Test
    public void test02() {
        //指定文件
        File f = new File("D:/a.txt");
        System.out.println("f.getName() = " + f.getName());
        //获取最后修改时间
        long l = f.lastModified();
        System.out.println("l = " + l);
        Date date = new Date(l);
        System.out.println("date = " + date);

        //[文件]大小 单位字节
        long length = f.length();
        System.out.println("length = " + length);//3


    }

    @Test
    public void test01() {
        //todo 创建File对象
        //文件
        File f = new File("D:\\classs_sources\\241028\\day00\\05_resources\\阿里Java开发手册黄山版2022.02.03V1.7.1.pdf");
        //文件夹
        File f2 = new File("D:\\classs_sources\\241028\\day00\\05_resources");
        System.out.println("f2.length() = " + f2.length());
        //                  父路径                                      子路径
        File f3 = new File("D:/classs_sources/241028/day00/05_resources", "jls8.pdf");

        System.out.println("f3 = " + f3);

    }
}
